#include "gtest/gtest.h"
#include "Range.h"

// Test that a range contains 1 value
TEST(testRange, Contains) {
    Range r(0, 10);
    ASSERT_EQ(true, r.Contains(2));
    ASSERT_FALSE(r.Contains(-5));
}

// Test that a range contains another range
TEST(testRange, ContainsRange) {
    Range r(-5, 10);
    // Test same value to same value range
    ASSERT_TRUE(r.Contains(6, 6));
    ASSERT_FALSE(r.Contains(11, 11));
    // Test negative to postive range
    ASSERT_TRUE(r.Contains(-4, 4));
    ASSERT_FALSE(r.Contains(-10, 10));
    // Test positive to positive range
    ASSERT_TRUE(r.Contains(5, 8));
    ASSERT_FALSE(r.Contains(11, 13));
    // Test invalid range syntax
    ASSERT_FALSE(r.Contains(8, 5));
}

// Use a fixture for multiple tests
class RangeFixture : public ::testing::Test {
protected:

    // SetUp gets called before any tests
    virtual void SetUp() {
        r.Add(-50, 50);
    }

    Range r;
};

// Test that a range was successfully added
TEST_F(RangeFixture, AddRange) {
    EXPECT_TRUE(r.Contains(1));
    EXPECT_TRUE(r.Contains(0));
    EXPECT_TRUE(r.Contains(-50, 50));
    EXPECT_FALSE(r.Contains(-51));
    EXPECT_FALSE(r.Contains(51));
}

TEST_F(RangeFixture, Remove) {
    r.Remove(1, 1);
    EXPECT_FALSE(r.Contains(1));
}

TEST_F(RangeFixture, RemoveRange) {
    r.Remove(5, 8);
    EXPECT_FALSE(r.Contains(5, 8));
    // Remove first/last value and get start/end
    r.Remove(-50, -50);
    EXPECT_EQ(-49, r.getStart());
    r.Remove(50, 50);
    EXPECT_EQ(49, r.getEnd());
}

int main(int argc, char **argv) {
    // Checks for any Google Test specific command line arguments
    ::testing::InitGoogleTest(&argc, argv);
    // Executes all tests
    return RUN_ALL_TESTS();
}   
